#include <stdio.h>
#include <unistd.h>
#include <sys/shm.h>

// 共享内存读进程

int main()
{
    //1.获取共享内存
    int shm_id = shmget(0x12121212,1024,IPC_CREAT | 0664);
    if(shm_id < 0)
    {
        perror("shmget error\n");
        return 0;
    }
    //2.进程附加
    void* shm_add = shmat(shm_id,NULL,SHM_RDONLY);
    if(shm_add == NULL)
    {
        perror("shmat wrong\n");
        return 0;
    }
    printf("read_shm add:%p\n",shm_add);
    //3.读 打印
    printf("read_shm:%s\n",(char*)shm_add);
    //4.进程分离
    getchar();
    shmdt(shm_add);

    return 0;
}
